package com.ruoyi.system.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.system.domain.WebSite;
import com.ruoyi.system.mapper.WebSiteMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.WebCateMapper;
import com.ruoyi.system.domain.WebCate;
import com.ruoyi.system.service.IWebCateService;
import com.ruoyi.common.core.text.Convert;

/**
 * 分类Service业务层处理
 * 
 * @author ruoyi
 * @date 2021-07-13
 */
@Service
public class WebCateServiceImpl implements IWebCateService 
{
    @Autowired
    private WebCateMapper webCateMapper;

    @Autowired
    private WebSiteMapper webSiteMapper;

    /**
     * 查询分类
     * 
     * @param id 分类ID
     * @return 分类
     */
    @Override
    public WebCate selectWebCateById(Long id)
    {
        return webCateMapper.selectWebCateById(id);
    }

    /**
     * 查询分类列表
     * 
     * @param webCate 分类
     * @return 分类
     */
    @Override
    public List<WebCate> selectWebCateList(WebCate webCate)
    {
        List<WebCate> cates = webCateMapper.selectWebCateList(webCate);
        for (WebCate cate:cates){
            WebSite webSite = new WebSite();
            webSite.setCateId(cate.getId());
            webSite.setSource(0);
            webSite.setSerialNum("xlh");
            List<WebSite> webSites = webSiteMapper.selectWebSiteList(webSite);
            cate.setWebSiteNum(webSites.size());
        }
        return cates;
    }

    /**
     * 新增分类
     * 
     * @param webCate 分类
     * @return 结果
     */
    @Override
    public int insertWebCate(WebCate webCate)
    {
        webCate.setCreateTime(DateUtils.getNowDate());
        return webCateMapper.insertWebCate(webCate);
    }

    /**
     * 修改分类
     * 
     * @param webCate 分类
     * @return 结果
     */
    @Override
    public int updateWebCate(WebCate webCate)
    {
        webCate.setUpdateTime(DateUtils.getNowDate());
        return webCateMapper.updateWebCate(webCate);
    }

    /**
     * 删除分类对象
     * 
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteWebCateByIds(String ids)
    {
        return webCateMapper.deleteWebCateByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除分类信息
     * 
     * @param id 分类ID
     * @return 结果
     */
    @Override
    public int deleteWebCateById(Long id)
    {
        return webCateMapper.deleteWebCateById(id);
    }
}
